/*
 * Copyright © 2023
 * @Author: zhangxiang
 * @Date: 2023-09-05 09:39:27
 * @LastEditors: zhangxiang
 * @LastEditTime: 2023-09-27 15:33:48
 * @Description:
 *
 */

import { mapGetters } from 'vuex'
import { isEmptyString } from '@/utils/index'
import { getCloudProviderItem } from '@/utils/cnap/constant'

export default {
  data() {
    return {}
  },
  computed: {
    ...mapGetters(['cloudVendors']),
    cloudVendorValue() {
      return ''
    },
    cloudVendorParams() {
      const arr = this.cloudVendorValue.split('$$')
      return {
        cloudVendor: arr.length > 0 ? arr[0] : this.cloudVendorValue,
        accountName: arr.length > 1 ? arr[1] : ''
      }
    }
  },
  watch: {},
  mounted() { },
  methods: {
    /**
     * @description: 拆分云商参数 包括 cloudVendor accountName
     * @param {*} cloudVendorValue
     * @return {*}
     */
    splitCloudVendorParams(cloudVendorValue) {
      const arr = cloudVendorValue.split('$$')
      return {
        cloudVendor: arr.length > 0 ? arr[0] : cloudVendorValue,
        accountName: arr.length > 1 ? arr[1] : ''
      }
    },
    /**
     * @description: 格式化 云商
     * @param {*} vendor
     * @param {*} account
     * @return {*}
     */
    formatVendorAccount(vendor, account) {
      if (isEmptyString(vendor) && isEmptyString(account)) {
        return ''
      }
      return (vendor || '') + '$$' + (account || '')
    },
    /**
     * @description: 云商是否是私有云
     * @param {*} key
     * @return {*}
     */
    isCloudVendorPrivate(key) {
      const item = getCloudProviderItem(this.cloudVendors, key)
      return item && item.cloudScope === 'private'
    },
    /**
     * @description: 获取云商中文
     * @param {*} en
     * @return {*}
     */
    getCloudVendorChn(en) {
      const item = getCloudProviderItem(this.cloudVendors, en)
      return item ? item.cloudName : en
    },
    /**
     * @description: 获取云商英文
     * @param {*} chn
     * @return {*}
     */
    getCloudVendorEn(chn) {
      const item = getCloudProviderItem(this.cloudVendors, chn)
      return item ? item.cloudVendor : chn
    },
    /**
     * @description: 获取云商图标
     * @param {*} key
     * @param {*} type 图标类型 normal mini logo
     * @return {*}
     */
    getCloudVendorImg(key, type = 'normal') {
      const item = getCloudProviderItem(this.cloudVendors, key)
      const cloudKey = item ? item.cloudVendor : ''
      const imgKey = cloudKey + (type !== 'normal' ? ('_' + type) : '')
      let imgSrc = ''
      try {
        imgSrc = require('@/assets/imgs/hybrid-cloud/' + imgKey + '.png')
      } catch (err) {
        console.log(err)
      }
      return imgSrc
    }
  }
}
